#ifndef GOOGLEPOSITIONING_H_
#define GOOGLEPOSITIONING_H_

#include <etel3rdparty.h> // CTelephony
#include <http\RHTTPTransaction.h>
#include <http\RHTTPSession.h>
#include <http\RHTTPHeaders.h>
#include <http\MHTTPDataSupplier.h>
#include <http\mhttptransactioncallback.h>
#include <lbs.h>
#include "ActiveTarget.h"
#include <es_sock.h>
#include <euserhl.h>

struct MGooglePositionRequestCallback
	{
	virtual void MGooglePositionRequestCallbackRunL(TInt aStatus, TInt aLastError, const TCoordinate& aCoordinate, TReal32 aAccuracy) = 0;
	};

class CGooglePositionRequest : private CActive, public MHTTPDataSupplier, public MHTTPTransactionCallback
	{
public:
	static CGooglePositionRequest* NewL();
	static CGooglePositionRequest* NewLC();
	virtual ~CGooglePositionRequest();
	void SubmitL(MGooglePositionRequestCallback* aTarget);
	void Cancel();
	virtual TBool GetNextDataPart(TPtrC8& aDataPart);
	virtual TInt OverallDataSize();
	virtual void ReleaseData();
	virtual TInt Reset();
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
	LManagedHandle<RTimer> iTimeoutTimer;
	LManagedPtr<scalp::CActiveTarget> iTimeoutTimerTarget;
	void TransactionTimeoutCallbackL();
	void SetConnectionInfoL(const RConnection& aConnection, const RSocketServ& aSocketServ);
	void CloseConnectionL();
	
protected:
	void RunL();
	TInt RunError(TInt aError);
	void DoCancel();
private:
	CTelephony* iTelephony;
	CTelephony::TNetworkInfoV1 iNwInfo;
	CTelephony::TNetworkInfoV1Pckg iNwInfoPckg;
	RHTTPSession iSession;
	RHTTPTransaction iTransaction;
	TBool iTransactionSubmitted;
	MGooglePositionRequestCallback* iTarget;
	HBufC8* iPostData;
	TInt iLastError;
	TInt iStatusCode;
	RBuf8 iBody;
	CGooglePositionRequest();
	void ConstructL();
	};

#endif /* GOOGLEPOSITIONING_H_ */
